package co.crossoft.configuration;


import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.ServiceBean;
import co.crossoft.service.ResourceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import co.crossoft.service.ExposeResourceService;
import co.crossoft.service.ExposeWorkCenterService;

/**
 * Created by ervin on 2017/8/2.
 */
@Configuration
public class DubboServiceConfiguration {

    @Autowired
    ApplicationConfig applicationConfig;

    @Autowired
    @Qualifier("dubboProtocolConfig")
    ProtocolConfig dubboProtocolConfig;

    @Autowired
    RegistryConfig registryConfig;

    @Bean
    public ServiceBean<ExposeResourceService> exposeResourceServiceConfig(ExposeResourceService exposeResourceService) {
        ServiceBean<ExposeResourceService> serviceBean = new ServiceBean<ExposeResourceService>();
        serviceBean.setInterface(ExposeResourceService.class.getName());
        serviceBean.setRef(exposeResourceService);
        serviceBean.setVersion("1.0");
        serviceBean.setRetries(0);
        serviceBean.setProtocol(dubboProtocolConfig);
        serviceBean.setApplication(applicationConfig);
        return serviceBean;
    }

    @Bean
    public ServiceBean<ExposeWorkCenterService> exposeWorkCenterServiceConfig(ExposeWorkCenterService exposeWorkCenterService) {
        ServiceBean<ExposeWorkCenterService> serviceBean = new ServiceBean<ExposeWorkCenterService>();
        serviceBean.setInterface(ExposeWorkCenterService.class.getName());
        serviceBean.setRef(exposeWorkCenterService);
        serviceBean.setVersion("1.0");
        serviceBean.setRetries(0);
        serviceBean.setProtocol(dubboProtocolConfig);
        serviceBean.setApplication(applicationConfig);
        return serviceBean;
    }

    @Bean
    public ServiceBean<ResourceTypeService> resourceTypeServiceConfig(ResourceTypeService resourceTypeService) {
        ServiceBean<ResourceTypeService> serviceBean = new ServiceBean<ResourceTypeService>();
        serviceBean.setInterface(ResourceTypeService.class.getName());
        serviceBean.setRef(resourceTypeService);
        serviceBean.setVersion("1.0");
        serviceBean.setRetries(0);
        serviceBean.setProtocol(dubboProtocolConfig);
        serviceBean.setApplication(applicationConfig);
        return serviceBean;
    }

}
